package com.feign.feignClient.coder;

import com.alibaba.fastjson.JSONObject;
import feign.RequestTemplate;
import feign.codec.EncodeException;
import feign.codec.Encoder;

import java.lang.reflect.Type;

/**
 * 自定义Encoder,使用阿里的FastJson
 */
public class MyEncoder implements Encoder {

    @Override
    public void encode(Object o, Type type, RequestTemplate requestTemplate) throws EncodeException {
        //将对象序列化，并设置到请求体的body
        requestTemplate.body(JSONObject.toJSONString(o));
        //进行请求
        requestTemplate.request();
    }


}
